<?php

// +---------------------------------------------+
// |     Copyright  2010 - 2018 InterPhoto       |
// |     http://www.weentech.com                 |
// |     This file may not be redistributed.     |
// +---------------------------------------------+

include('includes/Admin.Core.php');

CheckAccess('managesetting');


PrintHeader('基本设置');

// get the value of $action
$action = ForceIncomingString('action', 'displaysettings');


// ############################## UPDATE SETTINGS ##############################

if($action == 'updatesettings')
{
	$settings    = ForceIncomingArray('settings');

    foreach($settings as $key => $value)
	{
		if($mainsettings[$key] != $settings[$key]){
			$DB->query("UPDATE " . TABLE_PREFIX . "mainsettings SET value = '".ForceString($value)."' WHERE varname = '".ForceString($key)."'");
		}
	}

	if($mainsettings['siteDefaultTemplate'] != $settings['siteDefaultTemplate']){
		require_once (BASEPATH . 'library/smarty/libs/Smarty.class.php');
		$smarty = new Smarty;
		$smarty->compile_dir = BASEPATH.'library/smarty/templates_c/';
		$smarty->clear_compiled_tpl();
	}

	PrintRedirect('admin.mainsettings.php', 1);

}



// ############################### PRINT DEFAULT ###############################
if($action == 'displaysettings')
{

  echo '<form method="post" action="admin.mainsettings.php">
        <input type="hidden" name="action" value="updatesettings">';


    PrintSection('语言设置');
    echo '<table width="100%" border="0" cellpadding="5" cellspacing="0">
	<tr>
	<td class="tdrow1" colspan="2">前台默认语言</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">当选择 \'<b>自动</b>\' 时, 网站前台将根据用户的浏览器语言自动选择语言, 中文浏览器进入中文, 其它语言浏览器自动进入英文.</td>
	<td class="tdrow3" valign="top">';

	$Langs = GetLangs();

	$Select = NewObject('Select');
	$Select->Name = 'settings[siteDefaultLang]';
	$Select->SelectedValue = $mainsettings['siteDefaultLang'];
	$Select->AddOption('Auto', '自动');
	foreach($Langs as $val)
	{
		$Select->AddOption($val, $val);
	}

	echo $Select->Get();

	echo '</td></tr>';

    echo '</table>';

    EndSection();

// ##############################################################

    PrintSection('功能设置');
    echo '<table width="100%" border="0" cellpadding="5" cellspacing="0">
	<tr>
	<td class="tdrow1" colspan="2">URL友好访问模式(伪静态)</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">如果服务器是Apache环境, 且Rewrite重写模式有效, 可设置为 \'<b>开启</b>\', 有利于搜索引擎收录您的网页. 
<BR><BR>如果网站前台链接无效或访问不正常, 说明服务器不支持此功能, 需要重新设置为 \'<b>关闭</b>\'.</td>
	<td class="tdrow3" valign="top">';


	$Radio = NewObject('Radio');
	$Radio->Name = 'settings[siteRewrite]';
	$Radio->SelectedID = $mainsettings['siteRewrite'];
	$Radio->AddOption(1, '开启', '&nbsp;&nbsp;');
	$Radio->AddOption(0, '关闭', '&nbsp;&nbsp;');

	echo $Radio->Get();

	echo '</td></tr>';

	echo '<tr>
	<td class="tdrow1" colspan="2">游客访问</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">是否开放或禁止游客访问网站?<BR><BR>如果设置为 \'<b>禁止</b>\', 那么所有用户需要登录后才能访问网站.</td>
	<td class="tdrow3" valign="top">';

	$Radio->Clear();
	$Radio->Name = 'settings[siteAllowGuest]';
	$Radio->SelectedID = $mainsettings['siteAllowGuest'];
	$Radio->AddOption(1, '开放', '&nbsp;&nbsp;');
	$Radio->AddOption(0, '禁止', '&nbsp;&nbsp;');

	echo $Radio->Get();

	echo '</td></tr>';

	echo '<tr>
	<td class="tdrow1" colspan="2">用户注册</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">是否开放或禁止网站前台用户注册?</td>
	<td class="tdrow3" valign="top">';

	$Radio->Clear();
	$Radio->Name = 'settings[siteAllowRegister]';
	$Radio->SelectedID = $mainsettings['siteAllowRegister'];
	$Radio->AddOption(1, '开放', '&nbsp;&nbsp;');
	$Radio->AddOption(0, '禁止', '&nbsp;&nbsp;');
	$Radio->Attributes = " onclick=\"if(this.value==1){EnableID('siteRegisterCheck');}else{DisableID('siteRegisterCheck');}\"";

	echo $Radio->Get();

	echo '</td></tr>';

	echo '<tr>
	<td class="tdrow1" colspan="2">注册验证</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">当用户注册开放时, 验证用户注册的方式. 当设置为 \'<b>不验证</b>\' 时, 注册后立即享有注册会员资格.</td>
	<td class="tdrow3" valign="top">';

	$Select->Clear();
	$Select->Name = 'settings[siteRegisterCheck]';
    $Select->Attributes = " id='siteRegisterCheck'";
	if($mainsettings['siteAllowRegister'] == '0'){
		$Select->Attributes .= " disabled='disabled'";
	}
	$Select->SelectedValue = $mainsettings['siteRegisterCheck'];

	$Select->AddOption('Auto', '不验证');
	$Select->AddOption('EmailVerify', '邮件验证');
	$Select->AddOption('AdminVerify', '人工审核');

	echo $Select->Get();

	echo '</td></tr>';

	echo '<tr>
	<td class="tdrow1" colspan="2">网站默认模板</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">选择网站前台默认模板. 模板存放在./templates/文件夹.</td>
	<td class="tdrow3" valign="top">';

	$Templates = GetTemps();

	$Select->Clear();
	$Select->Name = 'settings[siteDefaultTemplate]';
	$Select->SelectedValue = $mainsettings['siteDefaultTemplate'];
	foreach($Templates as $val)
	{
		$Select->AddOption($val, $val);
	}

	echo $Select->Get();

	echo '</td></tr>';

	echo '<tr>
	<td class="tdrow1" colspan="2">默认每页图片数</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">网站前台默认每页图片数量.</td>
	<td class="tdrow3" valign="top">';
	$Select->Clear();
	$Select->Name = 'settings[siteNumPerpage]';
	$Select->SelectedValue = $mainsettings['siteNumPerpage'];
	$Select->AddOption(5, '5');
	$Select->AddOption(10, '10');
	$Select->AddOption(15, '15');
	$Select->AddOption(20, '20');
	$Select->AddOption(30, '30');
	$Select->AddOption(40, '40');
	$Select->AddOption(50, '50');
	$Select->AddOption(60, '60');

	echo $Select->Get();

	echo '</td></tr>';

	echo '<tr>
	<td class="tdrow1" colspan="2">管理员Cookie过期时间</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">管理员处于不活动状态, 需要重新登录的时间间隔(秒).</td>
	<td class="tdrow3" valign="top">
	<input type="text" size="40" name="settings[adminCookieTimeout]" value="' . $mainsettings['adminCookieTimeout'] . '">
	</td></tr>';

	echo '<tr>
	<td class="tdrow1" colspan="2">网站默认时区</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">'.APP_NAME.'图片网站系统将按默认时区显示日期和时间.</td>
	<td class="tdrow3" valign="top">';

	$Select->Clear();
	$Select->Name = 'settings[siteTimezone]';
	$Select->SelectedValue = $mainsettings['siteTimezone'];
	$Select->AddOption(-12, '(GMT -12) Eniwetok,Kwajalein');
	$Select->AddOption(-11, '(GMT -11) Midway Island,Samoa');
	$Select->AddOption(-10, '(GMT -10) Hawaii');
	$Select->AddOption(-9, '(GMT -9) Alaska');
	$Select->AddOption(-8, '(GMT -8) Pacific Time(US & Canada)');
	$Select->AddOption(-7, '(GMT -7) Mountain Time(US & Canada)');
	$Select->AddOption(-6, '(GMT -6) Mexico City');
	$Select->AddOption(-5, '(GMT -5) Bogota,Lima');
	$Select->AddOption(-4, '(GMT -4) Caracas,La Paz');
	$Select->AddOption(-3, '(GMT -3) Brazil,Buenos Aires,Georgetown');
	$Select->AddOption(-2, '(GMT -2) Mid-Atlantic');
	$Select->AddOption(-1, '(GMT -1) Azores,CapeVerde Islands');
	$Select->AddOption(0, '(GMT) London,Lisbon,Casablanca');
	$Select->AddOption(1, '(GMT +1) Paris,Brussels,Copenhagen');
	$Select->AddOption(2, '(GMT +2) Kaliningrad,South Africa');
	$Select->AddOption(3, '(GMT +3) Moscow,Baghdad,Petersburg');
	$Select->AddOption(4, '(GMT +4) Abu Dhabi,Muscat,Baku,Tbilisi');
	$Select->AddOption(5, '(GMT +5) Karachi,Islamabad,Tashkent');
	$Select->AddOption(6, '(GMT +6) Almaty,Dhaka,Colombo');
	$Select->AddOption(7, '(GMT +7) Bangkok,Hanoi,Jakarta');
	$Select->AddOption(8, '(GMT +8) 北京, 香港, 新加坡');
	$Select->AddOption(9, '(GMT +9) Tokyo,Osaka,Yakutsk');
	$Select->AddOption(10, '(GMT +10) Australia,Guam,Vladivostok');
	$Select->AddOption(11, '(GMT +11) Magadan,Solomon Islands');
	$Select->AddOption(12, '(GMT +12) Auckland,Wellington,Fiji');

	echo $Select->Get();

	echo '</td></tr>';

	echo '<tr>
	<td class="tdrow1" colspan="2">日期时间格式</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">系统显示日期和时间的格式. 如: Y.m.d H:i:s等, 日期和时间之间以空格分开.</td>
	<td class="tdrow3" valign="top">
	<input type="text" size="40" name="settings[siteDateFormat]" value="' . $mainsettings['siteDateFormat'] . '">
	</td></tr>
	</table>';

    EndSection();

// ##############################################################

    PrintSection('网站设置');
    echo '<table width="100%" border="0" cellpadding="5" cellspacing="0">
	<tr>
	<td class="tdrow1" colspan="2">开启或关闭网站</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">当系统进行升级, 数据库备份或恢复等维护操作时, 推荐先关闭网站.</td>
	<td class="tdrow3" valign="top">';
	$Radio ->Clear();
	$Radio->Name = 'settings[siteActived]';
	$Radio->SelectedID = $mainsettings['siteActived'];
	$Radio->AddOption(1, '开启', '&nbsp;&nbsp;');
	$Radio->AddOption(0, '关闭', '&nbsp;&nbsp;');
	$Radio->Attributes = " onclick=\"if(this.value==0){EnableID('siteOffTitle');}else{DisableID('siteOffTitle');}\"";

	echo $Radio->Get();

	echo '</td></tr>';

	echo '<tr>
	<td class="tdrow1" colspan="2">关闭时显示</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">网站关闭后显示的提示信息(允许HTML).</td>
	<td class="tdrow3" valign="top">
	<textarea name="settings[siteOffTitle]" rows="4" cols="36" id="siteOffTitle" '.Iif($mainsettings['siteActived'], ' disabled="disabled"').'>' . $mainsettings['siteOffTitle'] . '</textarea>
	</td></tr>';

	echo '<tr>
	<td class="tdrow1" colspan="2">网站名称</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">显示在网站页面底部等处的版权信息, 邮件中显示的网站名称.</td>
	<td class="tdrow3" valign="top">
	<input type="text" size="40" name="settings[siteCopyright]" value="' . $mainsettings['siteCopyright'] . '">
	</td></tr>';

	echo '<tr>
	<td class="tdrow1" colspan="2">网站标题</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">显示在浏览器上方的网站Title标题.</td>
	<td class="tdrow3" valign="top">
	<input type="text" size="40" name="settings[siteTitle]" value="' . $mainsettings['siteTitle'] . '">
	</td></tr>';

	echo '<tr>
	<td class="tdrow1" colspan="2">Meta关键字</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">便于搜索引擎收录和搜索您的网站, 多个Meta关键字需用英文逗号隔开.</td>
	<td class="tdrow3" valign="top">
	<input type="text" size="40" name="settings[siteKeywords]" value="' . $mainsettings['siteKeywords'] . '">
	</td></tr>';

	echo '<tr>
	<td class="tdrow1" colspan="2">Meta描述</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">网站页面中的Meta描述, 便于搜索引擎收录和搜索您的网站.</td>
	<td class="tdrow3" valign="top">
	<input type="text" size="40" name="settings[siteMeta]" value="' . $mainsettings['siteMeta'] . '">
	</td></tr>';

	echo '<tr>
	<td class="tdrow1" colspan="2">网站备案信息</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">在网站页面底部添加备案信息链接(不填可留空).</td>
	<td class="tdrow3" valign="top">
	<input type="text" size="40" name="settings[siteBeian]" value="' . $mainsettings['siteBeian'] . '">
	</td></tr>';

	echo '</table>';

    EndSection();

    PrintSection('邮件设置');
    echo '<table width="100%" border="0" cellpadding="5" cellspacing="0">
	<tr>
	<td class="tdrow1" colspan="2">网站Email地址</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">接收联系邮件, 及发送邮件时显示在邮件的回复地址中.</td>
	<td class="tdrow3" valign="top">
	<input type="text" size="40" name="settings[siteEmail]" value="' . $mainsettings['siteEmail'] . '">
	</td></tr>';

    echo '<tr>
	<td class="tdrow1" colspan="2">邮件发送方式</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">如果网站服务器是Windows系统, 则必须选择SMTP方式才能发送邮件(要求服务器php环境支持Sockets).
<BR><BR>UNIX或linux服务器则推荐使用PHP Mail函数发送邮件.</td>
	<td class="tdrow3" valign="top">';

	$Radio ->Clear();
	$Radio->Name = 'settings[siteUseSmtp]';
	$Radio->SelectedID = $mainsettings['siteUseSmtp'];
	$Radio->AddOption(0, 'PHP Mail', '&nbsp;&nbsp;');
	$Radio->AddOption(1, 'SMTP', '&nbsp;&nbsp;');
	$Radio->Attributes = " onclick=\"if(this.value==1){ShowDIV('div_smtp_settings');}else{HideDIV('div_smtp_settings');}\"";

	echo $Radio->Get();

	echo '</td></tr></table>';

	echo '<div id="div_smtp_settings" style="display: '.Iif($mainsettings['siteUseSmtp'], 'block', 'none').';"><table width="100%" border="0" cellpadding="5" cellspacing="0"><tr>
	<td class="tdrow1" colspan="2">-- SMTP服务器地址</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">如: mailer.weentech.com 或SMTP邮件服务器IP地址.</td>
	<td class="tdrow3" valign="top">
	<input type="text" size="40" name="settings[siteSmtpHost]" value="' . $mainsettings['siteSmtpHost'] . '">
	</td></tr>';

	echo '<tr>
	<td class="tdrow1" colspan="2">-- SMTP服务器端口</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">SMTP邮件服务器的端口号, 一般为25.</td>
	<td class="tdrow3" valign="top">
	<input type="text" size="40" name="settings[siteSmtpPort]" value="' . $mainsettings['siteSmtpPort'] . '">
	</td></tr>';

	echo '<tr>
	<td class="tdrow1" colspan="2">-- SMTP服务器邮箱</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">使用当前SMTP邮件服务器时您的Email地址, 此Email地址仅用于发送邮件, 不用于接收Email.</td>
	<td class="tdrow3" valign="top">
	<input type="text" size="40" name="settings[siteSmtpEmail]" value="' . $mainsettings['siteSmtpEmail'] . '">
	</td></tr>';

	echo '<tr>
	<td class="tdrow1" colspan="2">-- SMTP服务器邮箱用户名</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">登录SMTP服务器邮箱的用户名. 注: 有的SMTP服务器需求填写为用户名对应的邮箱地址.</td>
	<td class="tdrow3" valign="top">
	<input type="text" size="40" name="settings[siteSmtpUser]" value="' . $mainsettings['siteSmtpUser'] . '">
	</td></tr>';

	echo '<tr>
	<td class="tdrow1" colspan="2">-- SMTP服务器用户密码</td>
	</tr>
	<tr>
	<td class="tdrow2" width="60%">登录SMTP服务器邮箱的用户密码.</td>
	<td class="tdrow3" valign="top">
	<input type="password" size="40" name="settings[siteSmtpPassword]" value="' . $mainsettings['siteSmtpPassword'] . '">
	</td></tr>';

	echo '</table></div>';

    EndSection();

	PrintSubmit('updatesettings', '保存设置');
	echo '</form>';

}


// ############################### PRINT FOOTER ################################

PrintFooter();

?>